package com.github.dengmin.mysql.mapper;

import com.github.dengmin.mysql.model.DatabaseTable;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

/**
 * @Author dengmin
 * @Created 2020/6/17 下午2:38
 */
public class TableRowMapper implements RowMapper<DatabaseTable> {
    private static final long serialVersionUID = 1L;

    @Override
    public DatabaseTable mapRow(ResultSet rs, int i) throws SQLException {
        DatabaseTable table = new DatabaseTable();
        table.setSchema(rs.getString("TABLE_SCHEMA"));
        table.setName(rs.getString("TABLE_NAME"));
        table.setEngine(rs.getString("ENGINE"));
        table.setRowFormat(rs.getString("ROW_FORMAT"));
        table.setRows(rs.getLong("TABLE_ROWS"));
        table.setDataLength(rs.getLong("DATA_LENGTH"));
        table.setCreateTime(new Date(rs.getTimestamp("CREATE_TIME").getTime()));
        table.setTableCollation(rs.getString("TABLE_COLLATION"));
        table.setComment(rs.getString("TABLE_COMMENT"));
        return table;
    }
}
